using Engine;
using Game;

namespace SCIENEW {
    public class SubsystemNPickables : SubsystemPickables, IUpdateable {

        public new void Update(float dt) {
            base.Update(dt);
            //掉落物丢铁水里被烧
            double totalElapsedGameTime = m_subsystemGameInfo.TotalElapsedGameTime;
            foreach (Pickable pickable in m_pickables) {
                if (!pickable.ToRemove) {
                    int num3 = m_pickables.Count - m_pickablesToRemove.Count;
                    float num4 = MathUtils.Lerp(300f, 90f, MathUtils.Saturate(num3 / 60f));
                    double num5 = totalElapsedGameTime - pickable.CreationTime;
                    if (num5 <= num4) {
                        TerrainChunk chunkAtCell = m_subsystemTerrain.Terrain.GetChunkAtCell(Terrain.ToCell(pickable.Position.X), Terrain.ToCell(pickable.Position.Z));
                        if (chunkAtCell != null
                            && chunkAtCell.State > TerrainChunkState.InvalidContents4) {
                            if (!pickable.FlyToPosition.HasValue) {
                                Block surfaceBlock = BlocksManager.Blocks[m_subsystemTerrain.Terrain.GetCellContents(Terrain.ToCell(pickable.Position.X), Terrain.ToCell(pickable.Position.Y + 0.1f), Terrain.ToCell(pickable.Position.Z))];
                                if (surfaceBlock is MoltenIronBlock or MoltenSteelBlock
                                    && !pickable.SplashGenerated) {
                                    m_subsystemParticles.AddParticleSystem(new MagmaSplashParticleSystem(m_subsystemTerrain, pickable.Position, large: false));
                                    m_subsystemAudio.PlayRandomSound(
                                        "Audio/Sizzles",
                                        1f,
                                        m_random.Float(-0.2f, 0.2f),
                                        pickable.Position,
                                        3f,
                                        autoDelay: true
                                    );
                                    pickable.ToRemove = true;
                                    pickable.SplashGenerated = true;
                                    m_subsystemExplosions.TryExplodeBlock(Terrain.ToCell(pickable.Position.X), Terrain.ToCell(pickable.Position.Y), Terrain.ToCell(pickable.Position.Z), pickable.Value);
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}